#include <stdlib.h>
#include <stdio.h>
#include <linux/types.h>


#if 0 
/*added by wangxy for ddr-sdram debug */
void ddr_sdram_current_setting(void)
{
	int i;
	for(i = 0; i < 1; i++) {
		printf("\nDDR-SDRAM Settings: \n");
		printf("MC_DC00_ADDR: 0x%.8X\n", *MC_DC00_ADDR);
	}
}

void ddr_reg_set(void)
{

	/*start set reg00 to reg46*/
	*MC_DC00_ADDR = 0x00001B1B;
	
	/*
	 **MC_DC01_ADDR = 0x00000000;
	 **MC_DC02_ADDR = 0x00000000;
	 **MC_DC03_ADDR = 0x00000000;
	 **MC_DC04_ADDR = 0x00000000;
	 *these regs not need set
 	 */
	*MC_DC05_ADDR = 0x00000200;/*MC_DC05[11:8]=initared; MC_DC05[2:0]= max_cs_reg */
	*MC_DC03_ADDR = 0x00000100; /*MC_DC03, Activate controller*/	
}

/*first write cnt, then read it out */
/*void ddr_sdram_wrtest(void)
{
	ulong *addr;
	ulong cnt, value;
		
	for (addr = (ulong *)CFG_SDRAM_BASE, cnt = 1; 
		addr < CFG_SDRAM_BASE + CFG_DDR_SIZE*1024*1024; 
		addr += sizeof(ulong), cnt++){
		*addr = cnt;
		value = *addr;
								
		if(cnt%1024 == 0){
			printf("=>%d\n", cnt);
		}

		if(value != cnt){
			printf("Unmatch! Addr=0x%.8X, W=0x%.8X, R=0x%.8X\n", addr, cnt, value);
		}
	}
}*/
#endif
/*ended by wangxy*/
int main()
{
	ulong *ptr;
	int i;
	ulong *MC_DC00_ADDR,*MC_DC01_ADDR,*MC_DC02_ADDR,*MC_DC03_ADDR,*MC_DC04_ADDR,*MC_DC05_ADDR;
	ulong wxy;
	ptr = (ulong*) malloc(1024*1024);
	printf("ptr=%p\n", ptr);
	MC_DC00_ADDR=ptr + 0x000;
	MC_DC01_ADDR=ptr + 0x001;
	MC_DC02_ADDR=	ptr + 0x002;
	MC_DC03_ADDR=ptr + 0x003;
	MC_DC04_ADDR=	ptr + 0x004;
	MC_DC05_ADDR=	ptr + 0x005;

	*MC_DC00_ADDR = 0x1B1B;
	
	/*
	 **MC_DC01_ADDR = 0x00000000;
	 **MC_DC02_ADDR = 0x00000000;
	 **MC_DC03_ADDR = 0x00000000;
	 **MC_DC04_ADDR = 0x00000000;
	 *these regs not need set
 	 */
	*MC_DC05_ADDR = 0x00000200;/*MC_DC05[11:8]=initared; MC_DC05[2:0]= max_cs_reg */
	*MC_DC03_ADDR = 0x00000100; /*MC_DC03, Activate controller*/	
	for(i=0;i<6;i++)

		printf("MC_DC%02d_ADDR: 0x%.8X\n",i , *(ptr +i));
	wxy=(ulong)MC_DC00_ADDR;
	for(i=0;i<6;i++)
	
	printf("wxy=0x%.8X\n", *((ulong *)wxy + i*1));
	
	
	free(ptr);
	
	return  0;
}
